package com.mathdroid.gui.main.browser;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JTextField;

/**
 * This TextField's foreground color turns black if text is typed. Also all
 * text is selected if there is a mouse click noticed inside. The text of this
 * is used as a regular expression to filter items by their name.
 */
public class SearchField extends JTextField {

	/**
	 * Default UID.
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Create a new SearchField.
	 * @param width Width of the field.
	 * @param height height of the field.
	 */
	public SearchField(final int width, final int height) {
		super("Search ...");
		this.setForeground(Color.GRAY);
		Dimension d = new Dimension(width, height);
		this.setPreferredSize(d);
		this.setMaximumSize(d);
		SearchFieldListener listener = new SearchFieldListener(this);
		this.addMouseListener(listener);
		this.getDocument().addDocumentListener(listener);
		this.addKeyListener(listener);
	}
}
